$(document).ready(function() {	
	 $("#checkall").change(function(){
		if($("#checkall").attr("checked") ==  1)
			$(".atts").attr("checked", 1);
		else $(".atts").attr("checked", 0);
	 });
	 
	 $("#checking").submit(function(e){
			e.preventDefault();	
			checking();
		});
});

function checking(){
	var o = $("#checking").serializeArray();
	$.post("att_checking_do.php", o, function(data) {            
            if (data == 1){
                alert("Attendance taken and saved.");
            }
    }, 'html');
}
function goreport(){
	var class_id = $("#class_id").val();
	var month = $("#att_month").val();
	var year = $("#att_year").val();
        //alert(month);
        //alert(year);
	if(!(month > 0 && month <13)){
                
		alert("Month format is wrong.");
		return false;
	}
	if(!(year > 2008 && month < 2020)){
		alert("Year format is wrong.");
		return false;
	}
	window.location = '<?=SITE_URL?>'+"att_month.php?class_id="+class_id+"&month="+month+"&year="+year;
}
	function validate_date(str){
		var temp = new Array();
		temp = str.split('-');
		if(temp.length != 3) return 0;
		
		if(temp[0].length != 4 || temp[1].length != 2 || temp[2].length != 2 ) return 1;
		
		if(!isUnsignedInteger(temp[0]) || !isUnsignedInteger(temp[1]) || !isUnsignedInteger(temp[2])) return 2;
		
		if(temp[0] > 2009 || temp[0] < 1 || temp[1] > 12 || temp[1] < 1 || temp[2] > 31 || temp[2] < 1) return 3;
		
		return true;
	}
	
	function isUnsignedInteger(s) {
		return (s.toString().search(/^[0-9]+$/) == 0);
	}

function isUnsigned(s){
	return (s.toString().search(/^[0-9.]/)==0);
}

function PrintContent(id, document)
{
	var DocumentContainer = document.getElementById(id);
	var WindowObject = window.open("PrintWindow", "width=670,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
	WindowObject.document.writeln(DocumentContainer.innerHTML);
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
}
